//
//  EmojiTests.swift
//  UtilityTests
//
//  Created by yuhus on 2023/10/25.
//

import Foundation
import XCTest
import Nimble

final class EmojiTests: XCTestCase {
  
  override func setUpWithError() throws {
    // Put setup code here. This method is called before the invocation of each test method in the class.
  }
  
  override func tearDownWithError() throws {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
  }
  
  /// 系统判断存在的问题
  func testProperties() throws {
    // Swift 5.0，有一个新的 Unicode.Scalar.Properties 类
    expect("😀".unicodeScalars.first?.properties.isEmoji).to(beTrue())
    
    expect("3".unicodeScalars.first?.properties.isEmoji).to(beTrue(), description: "🔴")
    expect("3".unicodeScalars.first?.properties.isEmojiPresentation).to(beFalse(), description: "🟢")
    
    expect("🌶".unicodeScalars.first?.properties.isEmojiPresentation).to(beFalse(), description: "🔴")
    expect("🌶".unicodeScalars.first?.properties.generalCategory).to(equal(.otherSymbol), description: "🟢")
    
    // 还没有真正的成功。实际上还有一些字符由多个字形组成。
    expect("1️⃣".unicodeScalars.first?.properties.isEmojiPresentation).to(beFalse(), description: "🔴")
    expect("♦️".unicodeScalars.first?.properties.isEmojiPresentation ).to(beFalse(), description: "🔴")
    expect("👍🏻".unicodeScalars.first?.properties.isEmojiPresentation).to(beTrue(), description: "🟢")
    expect("👨👩👧👧".unicodeScalars.first?.properties.isEmojiPresentation).to(beTrue(), description: "🟢")
  }
  
  func testEmoji() throws {
    // 创建一个UnicodeScalarView
    let scalarView = "1️⃣".unicodeScalars
    // 映射视图，以便我们得到一个常规数组，可以检查
    let scalars = scalarView.map { $0 }
    print("1️⃣ =", "1️⃣".unicodeScalars.map { $0 })
    /// 结果包含三个值：
    /// 1. 十进制 49（十六进制U + 0031）：普通的旧数字1
    /// 2. 十进制65039（十六进制U + FE0F）：变量选择器16
    /// 3. 十进制8419（十六进制U + 20E3）：组合封闭键帽
    
    print("\u{0031}") //变成：1
    print("\u{0031}\u{20E3}") //变成：1⃣
    print("\u{0031}\u{FE0F}\u{20E3}")  //变成：1️⃣
    
    print("===========================")
    // 快捷键 ⌃⌘Space（ctrl + cmd + space）呼出 emoji 面板。
    print(#line, "A̛͚̖", "A̛͚̖".containsEmoji) // false
    print(#line, "3", "3".containsEmoji) // false
    print(#line, "A̛͚̖▶️", "A̛͚̖▶️".unicodeScalars) // [65, 795, 858, 790, 9654, 65039]
    print(#line, "A̛͚̖▶️", "A̛͚̖▶️".emojiScalars) // [9654, 65039]
    print(#line, "3️⃣", "3️⃣".isSingleEmoji) // true
    print(#line, "3️⃣", "3️⃣".emojiScalars) // [51, 65039, 8419]
    print(#line, "👌🏿", "👌🏿".isSingleEmoji) // true // MARK: - error
    print(#line, "🙎🏼♂️", "🙎🏼♂️".isSingleEmoji) // true // MARK: - error
    print(#line, "👨👩👧👧", "👨👩👧👧".isSingleEmoji) // true // MARK: - error
    print(#line, "👨👩👧👧", "👨👩👧👧".containsOnlyEmoji) // true
    print(#line, "Hello 👨👩👧👧", "Hello 👨👩👧👧".containsOnlyEmoji) // false
    print(#line, "Hello 👨👩👧👧", "Hello 👨👩👧👧".containsEmoji) // true
    print(#line, "👫 Héllo 👨👩👧👧", "👫 Héllo 👨👩👧👧".emojiString) // "👫👨👩👧👧"
    print(#line, "👨👩👧👧", "👨👩👧👧".count) // 1 // MARK: - error
    print(#line, "👫 Héllœ 👨👩👧👧", "👫 Héllœ 👨👩👧👧".emojiScalars) // [128107, 128104, 8205, 128105, 8205, 128103, 8205, 128103]
    print(#line, "👫 Héllœ 👨👩👧👧", "👫 Héllœ 👨👩👧👧".unicodeScalars.map { $0.value }) // [128107, 128104, 8205, 128105, 8205, 128103, 8205, 128103]
    print(#line, "👫 Héllœ 👨👩👧👧", "👫 Héllœ 👨👩👧👧".emojis) // ["👫", "👨👩👧👧"]  // MARK: - error
    print(#line, "👫 Héllœ 👨👩👧👧", "👫 Héllœ 👨👩👧👧".emojis.count) // 2
    print(#line, "👫👨👩👧👧👨👨👦", "👫👨👩👧👧👨👨👦".isSingleEmoji) // false
    print(#line, "👫👨👩👧👧👨👨👦", "👫👨👩👧👧👨👨👦".containsOnlyEmoji) // true
  }
  
  func testPerformanceExample() throws {
    // This is an example of a performance test case.
    self.measure {
      // Put the code you want to measure the time of here.
    }
  }
  
}
